<template>
  <div class="swiper">
    <swiper :options="swiperOptions"
            v-if="showSwiper">
      <swiper-slide v-for="item of list"
                    :key="item.id">
        <img class="swiper-img"
             :src="item.imgUrl">
      </swiper-slide>
      <div class="swiper-pagination"
           slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOptions: {
        pagination: '.swiper-pagination',
        autoplay: 3000
      }
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
// 因为scoped的作用 :只能影响当前组件，其他的不受影响。所以进行穿透操作
.swiper >>> .swiper-pagination-bullet-active
  background: #fff
.swiper
  overflow: hidden
  height: 0
  width: 100%
  padding-bottom: 25%
  background: #eee
  .swiper-img
    width: 100%
</style>
